package com.example.Laboratory.Controller;

import com.example.Laboratory.Entity.News;
import com.example.Laboratory.Service.NewsService;
import com.example.Laboratory.Untils.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@Api(value = "News",description = "新闻")
@RestController
@RequestMapping(value = "/News")
@CrossOrigin
public class NewsController {

    @Autowired
    NewsService newsservice;

    @ApiOperation(value = "添加新闻",notes = "添加新闻")
    @RequestMapping(value = "/addNews",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Object addnNews(News t, MultipartFile File1, MultipartFile File2)throws IOException {
        return ResultCode.SUCCESS.result(newsservice.addNews(t, File1, File2));
    }

    @ApiOperation(value = "删除新闻",notes = "删除新闻")
    @RequestMapping(value = "/deleteNews",method = RequestMethod.GET,produces = "application/json;charset=utf-8")
    public Object deleteNews(@RequestParam int news_id)throws IOException{
        return ResultCode.SUCCESS.result(newsservice.deleteNews(news_id));
    }


    @ApiOperation(value = "单条查找新闻",notes = "单条查找新闻")
    @RequestMapping(value = "/researchNews1",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Object researchNews1(int news_id)throws IOException{
        return ResultCode.SUCCESS.result(newsservice.researchNews1(news_id));
    }

    @ApiOperation(value = "多条查找新闻",notes = "多条查找新闻")
    @RequestMapping(value = "/researchNews2",method = RequestMethod.GET,produces = "application/json;charset=utf-8")
    public Object researchNews2()throws IOException{
        return ResultCode.SUCCESS.result(newsservice.researchNews2());
    }

    @ApiOperation(value = "修改新闻",notes = "修改新闻")
    @RequestMapping(value = "/reviseNews",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Object reviseNews(News t,MultipartFile File1)throws IOException{
        return ResultCode.SUCCESS.result(newsservice.reviseNews(t,File1));

    }

}
